import 'package:flutter_public/flutter_public.dart';

import '../model/test_model.dart';
import 'test_list_notifier.dart';

/// FileName test_detail_notifier
///
/// @Author lax
/// @Date 2024/6/4
///
/// @Description

class TestDetailNotifier extends PageNotifier {
  late TestModel model;

  TestDetailNotifier({TestModel? model}) {
    if (model == null) {
      this.model = TestModel();
    } else {
      this.model = model;
    }
    requestData();
  }

  @override
  Future<void> requestData() async {
    if (model.id == null) {
      return ;
    }
    final resp = await Api.get(
      base: TestListNotifier.base,
      url: 'api/manage/ap/ApInfo/GetApDetailMini',
      params: {'id': model.id},
    );
    pageStatusChanged(resp['Result'] != null);
    model = TestModel.fromJson(resp['Result']);
    notifyListeners();
  }

  Future<bool> submitAction() async {
    var para = model.toJson();
    para['NeedSubmit'] = false;
    Loading.show();
    final resp = await Api.post(
      base: TestListNotifier.base,
      url: 'api/manage/ap/ApInfo/SaveAndSubmit',
      params: para,
    );
    Loading.dismiss();
    if (resp['Code'] == 200) {
      return true;
    }
    return false;
  }
}
